package com.github.sort;

import java.util.*;
import java.util.stream.Collectors;

/**
 * Description:
 *
 * @author zwl
 * @version 1.0
 * @date 2021/7/30 下午5:01
 */
public class TestLamdaSort {

    public static void main(String[] args) {

        //ArrayList<Integer> list = new ArrayList<>();
        //
        //list.add(2);
        //list.add(4);
        //list.add(2);
        //list.add(1);
        //list.add(2);
        //
        //List<Integer> collect = list.stream()
        //        .sorted(Comparator.comparingInt(a -> a))
        //        .collect(Collectors.toList());
        //
        //System.out.println(collect);

        List<Buss> bussList = new ArrayList<>();
        bussList.add(new Buss("a", 10, 0.3));
        bussList.add(new Buss("b", 3, 0.8));
        bussList.add(new Buss("c", 5, 2.0));
        bussList.add(new Buss("b", 30, 3.2));
        bussList.add(new Buss("c", 20, 0.1));

        List<Buss> res = new ArrayList<>();
        bussList.stream()
                .collect(Collectors.groupingBy(Buss::getName))
                .forEach((name, list) -> {
                    System.out.println(name);
                    System.out.println(list.toString());
                    Optional<Buss> buss = list.stream().max(Comparator.comparingInt(a -> a.count));
                    buss.ifPresent(res::add);
                });

        System.out.println(res.size());

    }

    static class Buss {

        private String name;
        private int count;
        private double value;

        public Buss(String name, int count, double value) {
            this.name = name;
            this.count = count;
            this.value = value;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getCount() {
            return count;
        }

        public void setCount(int count) {
            this.count = count;
        }

        public double getValue() {
            return value;
        }

        public void setValue(double value) {
            this.value = value;
        }

        @Override
        public String toString() {
            return "Buss{" +
                    "name='" + name + '\'' +
                    ", count=" + count +
                    ", value=" + value +
                    '}';
        }
    }

}
